package com.czkevin.cifjiaocheng.cif;

import com.czkevin.cifjiaocheng.SoundUtil;
import de.tr7zw.nbtapi.NBTCompound;
import com.czkevin.cif.BaseBlock;
import com.czkevin.cif.CIFItemInstance;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.SoundCategory;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class ShitOre extends BaseBlock {

    @Override
    public String getDisplayName(NBTCompound nbtCompound) {
        return "\u00a76\u00a7l大粪矿";
    }

    @Override
    public Material getModelMaterial() {
        return Material.DIAMOND;
    }

    @Override
    public int getCustomModelData(CIFItemInstance instance) {
        return 114514100;
    }

    /**
     * 点击大粪矿会导致眩晕效果
     * @param instance
     * @param event
     */
    @Override
    public void onBlockUse(CIFItemInstance instance, PlayerInteractEvent event) {
        if(event.getHand() != EquipmentSlot.HAND) return;
        event.getPlayer().sendMessage("\u00a7d\u00a7l你触碰了大粪矿，被熏到了。\n\u00a7c\u00a7l获得了5秒的反胃效果和中毒效果！");
        event.getPlayer().addPotionEffect(
            new PotionEffect(
                PotionEffectType.CONFUSION,
                100,
                1000,
                false,
                false,
                false
            )
        );
        event.getPlayer().addPotionEffect(
            new PotionEffect(
                PotionEffectType.POISON,
                100,
                1000,
                false,
                false,
                false
            )
        );
        // 播放哼哼哼的声音
        Location location = event.getClickedBlock().getLocation();
        location.getWorld().playSound(
            location, "jiaocheng.heng.random",
            SoundCategory.BLOCKS,
            1.0f, // 音♂量
            SoundUtil.randomPitch()
        );
    }
}
